package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DataCollection;
import com.ruoyi.system.service.IDataCollectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据采集结果汇总Controller
 * 
 * @author ruoyi
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/system/collection")
public class DataCollectionController extends BaseController
{
    @Autowired
    private IDataCollectionService dataCollectionService;

    /**
     * 查询数据采集结果汇总列表
     */
    @PreAuthorize("@ss.hasPermi('system:collection:list')")
    @GetMapping("/list")
    public TableDataInfo list(DataCollection dataCollection)
    {
        startPage();
        List<DataCollection> list = dataCollectionService.selectDataCollectionList(dataCollection);
        return getDataTable(list);
    }

    /**
     * 导出数据采集结果汇总列表
     */
    @PreAuthorize("@ss.hasPermi('system:collection:export')")
    @Log(title = "数据采集结果汇总", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataCollection dataCollection)
    {
        List<DataCollection> list = dataCollectionService.selectDataCollectionList(dataCollection);
        ExcelUtil<DataCollection> util = new ExcelUtil<DataCollection>(DataCollection.class);
        util.exportExcel(response, list, "数据采集结果汇总数据");
    }

    /**
     * 获取数据采集结果汇总详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:collection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(dataCollectionService.selectDataCollectionById(id));
    }

    /**
     * 新增数据采集结果汇总
     */
    @PreAuthorize("@ss.hasPermi('system:collection:add')")
    @Log(title = "数据采集结果汇总", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataCollection dataCollection)
    {
        return toAjax(dataCollectionService.insertDataCollection(dataCollection));
    }

    /**
     * 修改数据采集结果汇总
     */
    @PreAuthorize("@ss.hasPermi('system:collection:edit')")
    @Log(title = "数据采集结果汇总", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataCollection dataCollection)
    {
        return toAjax(dataCollectionService.updateDataCollection(dataCollection));
    }

    /**
     * 删除数据采集结果汇总
     */
    @PreAuthorize("@ss.hasPermi('system:collection:remove')")
    @Log(title = "数据采集结果汇总", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dataCollectionService.deleteDataCollectionByIds(ids));
    }
}
